package com.argerie.robot;

import com.argerie.robot.MyLocation.LocationResult;

import android.app.Activity;
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

public class GpsControls extends Activity {
    /** Called when the activity is first created. */
	
	MyLocation myLocation = new MyLocation();
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gps_layout);
        locationClick();
/*     // Acquire a reference to the system Location Manager
        LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

        // Define a listener that responds to location updates
        LocationListener locationListener = new LocationListener() {
            public void onLocationChanged(Location location) {
              // Called when a new location is found by the network location provider.
              makeUseOfNewLocation(location);
            }

            public void onStatusChanged(String provider, int status, Bundle extras) {}

            public void onProviderEnabled(String provider) {}

            public void onProviderDisabled(String provider) {}
          };

        // Register the listener with the Location Manager to receive location updates
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
        */
    }

    private void locationClick() {
        myLocation.getLocation(this, locationResult);
    }

    public LocationResult locationResult = new LocationResult(){
        @Override
        public void gotLocation(final Location location){
            //Got the location!
        	TextView lat_loc = (TextView)findViewById(R.id.lat_location);
        	TextView long_loc = (TextView)findViewById(R.id.long_location);
        	lat_loc.setText(((Double)location.getLatitude()).toString());
        	long_loc.setText(((Double)location.getLongitude()).toString());
            }
        };

	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_data, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    	switch (item.getItemId()) {
    		case R.id.gps_menu:          
    			Toast.makeText(this, "Already There!", Toast.LENGTH_SHORT).show();
    			break;
    		case R.id.main:
    			Intent myIntent = new Intent(GpsControls.this, BasicRobotControls.class);
    			GpsControls.this.startActivity(myIntent);
    	}
    	return(super.onOptionsItemSelected(item));
    }
}